{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "test3.xlsx\n",
      "[u'\\u5b66\\u751f', u'\\u5e74\\u7ea7']\n",
      "(<xlrd.sheet.Sheet object at 0x000000000502D390>, <xlrd.sheet.Sheet object at 0x000000000502D908>)\n",
      "(u'\\u5b66\\u751f', 7, 4)\n",
      "李四\n",
      "11.0\n",
      "39275.0\n",
      "\n",
      "爱好\n",
      "打游戏\n",
      "\n",
      "看书\n",
      "打篮球\n",
      "\n",
      "\n",
      "张三\n",
      "张三\n",
      "张三\n"
     ]
    }
   ],
   "source": [
    "#! /usr/bin/python\n",
    "# -*- coding:utf-8 -*-\n",
    "\n",
    "import xlrd\n",
    "from datetime import date,datetime\n",
    "import sys\n",
    "\n",
    "\n",
    "\n",
    "file = 'test3.xlsx'\n",
    "print file\n",
    "\n",
    "def read_excel():\n",
    "\n",
    "    wb = xlrd.open_workbook(filename=file)#打开文件\n",
    "    print(wb.sheet_names())#获取所有表格名字\n",
    "\n",
    "    sheet1 = wb.sheet_by_index(0)#通过索引获取表格\n",
    "    #sheet2 = wb.sheet_by_name('年级')#通过名字获取表格\n",
    "    sheet2 = wb.sheet_by_index(1)#通过名字获取表格\n",
    "    print(sheet1,sheet2)\n",
    "    print(sheet1.name,sheet1.nrows,sheet1.ncols)\n",
    "\n",
    "    rows = sheet1.row_values(2)#获取行内容\n",
    "    cols = sheet1.col_values(3)#获取列内容\n",
    "    #print rows\n",
    "    #print cols\n",
    "    for s1 in rows:\n",
    "        if type(s1) == 'str':\n",
    "            print(s1.encode(encoding='UTF-8'))\n",
    "        else:\n",
    "            print s1\n",
    "    for s2 in cols:\n",
    "        if type(s2) == 'str':\n",
    "            print(s2.encode(encoding='UTF-8'))\n",
    "        else:\n",
    "            print s2\n",
    "\n",
    "    print(sheet1.cell(1,0).value)#获取表格里的内容，三种方式\n",
    "    print(sheet1.cell_value(1,0))\n",
    "    print(sheet1.row(1)[0].value)\n",
    "    \n",
    "if __name__ == '__main__':\n",
    "    #reload(sys)\n",
    "    #sys.setdefaultencoding('gb18030')\n",
    "    read_excel()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<type 'str'>\n"
     ]
    }
   ],
   "source": [
    "print type('hello world')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.15"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
